<template>
  <div class="contain">
    <el-dialog
      title="分红权"
      :visible.sync="dividendRightVisible"
      width="850px"
      :before-close="dividendRightVisibleClose">
      <div class="report_header" ref="headerHeight">


        <div class="report_header report_header_contain" ref="headerHeight headerHeight_contain">
          <div class="report_header_left_wrap">
            <div class="report_header_left"></div>
            <div class="report_header_query" >
              <queryMember @queryMemberClick="queryMemberClick" :membername="membername"></queryMember>
              <!--              <el-date-picker v-model="date" value-format="yyyy-MM-dd" type="daterange" align="right"-->
<!--                              unlink-panels @change="changeTime" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">-->
<!--              </el-date-picker>-->

            </div>
          </div>
          <div class="queryClick_button_wrap">
            <el-button class="queryClick_button" size="small" type="primary" @click="dividendRightQueryClick">查询</el-button>
          </div>
        </div>

      </div>
      <div  class="el_table_wrap">
        <el-table :data="dividendCustomerTable" border stripe style="width: 100%;">
          <el-table-column label="序号" type="index" width="50" align="center" />
          <el-table-column label="会员名称" align="left" prop="name"  />
          <el-table-column label="手机号码" align="left" prop="mobile"/>
<!--          <el-table-column label="会员编号" align="left" prop="code" />-->
          <el-table-column label="分红权" align="left" prop="balance" width="110" />
          <el-table-column label="详情" align="center"  >
            <template slot-scope="scope">
              <el-button  size="mini" @click="detailsClick(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          v-if="dividendCustomerTable.length > 0"
          style="padding-top: 15px;"
          :current-page="pageNum"
          :page-sizes="[2,5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChangeMemberList"
        />
      </div>
    </el-dialog>
    <el-dialog
    title="分红权详情"
    :visible.sync="dividendRightDeatilVisible"
    width="850px"
    :before-close="dividendRightDeatilVisibleClose">
    <div class="report_header" ref="headerHeight">
      <div class="report_header report_header_contain" ref="headerHeight headerHeight_contain">
        <div class="report_header_left_wrap">
          <div class="report_header_left"></div>
          <div class="report_header_query">
            <el-date-picker v-model="date" value-format="yyyy-MM-dd" type="daterange" align="right"
                            unlink-panels @change="changeTime" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </div>
        <div class="queryClick_button_wrap">
          <el-button class="queryClick_button" size="small" type="primary" @click="dividendRightDeatilQueryClick">查询</el-button>
        </div>
      </div>
    </div>
    <div  class="el_table_wrap">
      <el-table :data="dividendCustomerDetailTable" border stripe style="width: 100%;">
        <el-table-column label="序号" type="index" width="50" align="center" />
        <el-table-column label="创建时间" align="left" width="170">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.createDate | datetimeFormatter }}</span>
          </template>
        </el-table-column>
        <el-table-column label="摘要" align="left" prop="memo" />
        <el-table-column label="余额" align="left" prop="balance" width="110" />
        <el-table-column label="收入" align="center" prop="credit" width="110" />
        <el-table-column label="支出" align="left" prop="debit" width="110" />
      </el-table>
      <el-pagination
        v-if="dividendCustomerDetailTable.length > 0"
        style="padding-top: 15px;"
        :current-page="pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChangeList"
      />
    </div>
  </el-dialog>
  </div>
</template>
<script>
  import utils from "@/utils/utils";
  import queryMember from '../../resultSaleReport/components/Query/queryMember'
  import { memberList , list } from "@/api/stockRight";

  export default {
    data() {
      return {
        membername:"",
        query:{
          type:"",
          memberId:''
        },
        dividendRightVisible:false,
        pageNum:1,
        pageSize:10,
        total: 0,
        dividendCustomerTable:[],
        dividendRightDeatilVisible:false,
        dividendCustomerDetailTable:[],
        date: [],
        memberListevent:{},
        listEvent:{}
      }
    },
    components: {
      queryMember,
    },
    created(){
    },
    methods: {
      detailsClick(item){
        this.list(item)
        this.dividendRightDeatilVisible = true
      },
      dividendRightDeatilQueryClick(){
        this.pageNum = 1
        this.list(this.listEvent)
      },
      list(item){
        this.listEvent = item
        let params ={
          // type: item.type,
          memberId: item.memberId,
          endDate:this.query.endDate,
          startDate:this.query.beginDate,
          pageNum:this.pageNum,
          pageSize:this.pageSize
        }
        list(params).then(res=>{
          this.dividendCustomerDetailTable = res.data.data
          this.total = res.data.total
        })
      },
      dividendRightQueryClick(){
        this.pageNum = 1
        this.memberList(this.memberListevent)
      },

      memberList(event){
        this.memberListevent = event
        let params ={
          type:  event.vipTwo,
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          memberId:this.query.memberId
        }
        memberList(params).then(res=>{
          this.dividendCustomerTable = res.data.data
          this.total = res.data.total

        })
      },
      openDividendRightVisible(event){
        this.query.memberId = event.memberId
        this.memberList(event)
        this.dividendRightVisible = true
      },
      dividendRightVisibleClose(){
        this.dividendRightVisible=false
        this.dividendCustomerTable = []
        this.pageSize = 10
        this.pageNum = 1
      },
      dividendRightDeatilVisibleClose(){
        this.dividendRightDeatilVisible =false
        this.dividendCustomerDetailTable = []
        this.pageSize = 10
        this.pageNum = 1
      },
      handleSizeChange(value) {
        this.pageSize = value
      },
      handleCurrentChangeMemberList(value) {
        this.pageNum = value
        this.memberList(this.memberListevent)
      },
      handleCurrentChangeList(value) {
        this.pageNum = value
        this.list(this.listEvent)
      },
      changeTime(data) {
        console.log(data)
        if (!utils.isNull(data)) {
          if (data.length > 1) {
            this.query.beginDate = data[0]
            this.query.endDate = data[1]
          }
        } else {
          this.query.beginDate = ''
          this.query.endDate = ''
        }
        // this.queryDateClick(this.query)

      },
      queryMemberClick(data){
        console.log(data)
        this.query.memberId = data.memberId
        this.membername=data.membername
      },
    }
  }
</script>

<style scoped>
  .report_header {
  display: flex;
  position: relative;
  margin-bottom: 10px;
  width: 100%;
  min-height: 40px;
  box-sizing: border-box;
  background-color: rgba(248, 248, 248, 0.8);
}
  .report_header_left {
    width: 5px;
    height: 46px;
    background-color: #409EFF;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
  }
  .report_header_left_wrap{
    display: flex;
    align-items: center;
  }
  .el_table_wrap{
    position: relative;
  }
  .el-dialog >>> .el-dialog__body {
    padding: 15px 20px !important;
  }
  .queryClick_button{
    margin-top: 5px;
    margin-left: 10px;
    margin-right: 10px;
  }
  .queryClick_button_wrap{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .report_header_query{
    margin-left: 20px;
    margin-top: 5px;

  }
</style>
